/**
 * 
 */
package org.dragonfire.editor.tibasic;

import org.dragonfire.editor.syntax.WordDoubleClickStrategy;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextDoubleClickStrategy;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
import org.eclipse.jface.text.rules.ITokenScanner;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;

/**
 * @author Darth Android
 * @date Dec 27, 2007
 */
public class TIBasicConfiguration extends SourceViewerConfiguration {

	private static WordDoubleClickStrategy clickStrategy = null;
	private TIBasicSyntaxScanner scanner = null;
	private int calcType;

	public TIBasicConfiguration(int calcType) {
		this.calcType = calcType;
	}

	@Override
	public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
		if (clickStrategy == null)
			clickStrategy = new WordDoubleClickStrategy("[A-z0-9]");
		return clickStrategy;
	}

	public ITokenScanner getSourceScanner() {
		if (scanner == null)
			scanner = new TIBasicSyntaxScanner(calcType);
		return scanner;
	}

	@Override
	public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
		PresentationReconciler reconciler = new PresentationReconciler();
		DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getSourceScanner());
		reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
		reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
		return reconciler;
	}
}
